package com.qd.p2p.web.action.additional;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.FinanFlowQueryService;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.dto.AdditionalFlowProject;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.model.FlowProjectModel;
import com.qdlc.p2p.dal.model.RepayPlanModel;

/**
 * 借款人个人中心理财项目action
 * @author wjx
 * @version 2.0
 * @date 2015年5月28日 下午4:28:43
 */
public class FlowBorrowAction extends BaseAction<FlowProjectModel> implements
ModelDriven<FlowProjectModel> {
	
	@Resource
	private FinanFlowQueryService finanFlowQueryService;
	
	private Map<String, Object> data;
	
	/**
	 * 借款人个人中心页面查看理财项目
	 * @return
	 */
	@Action(value = "/member_borrow/flow/myFlowProject",interceptorRefs = {
			@InterceptorRef("session"), @InterceptorRef("globalStack") })
	public String myFlowProject(){
		//User user = this.getSessionUser();
		return "myFlowProject";
	}
	
	/**
	 * 个人中心借款人理财项目json集合
	 * @throws IOException
	 */
	@Action(value="/member_borrow/flow/myFlowProjectJson",interceptorRefs = {
			@InterceptorRef("session"), @InterceptorRef("globalStack")})
	public void myFlowProjectJson() throws IOException{
		User user = this.getSessionUser();
		model.setUser(user);
		PageDataList<FlowProjectModel> list = finanFlowQueryService.getBorrowFlowProject(model);
		data =new HashMap<String, Object>();
		data.put("data", list);
		printWebJson(getStringOfJpaObj(data));
	}
	
	
	/**
	 * 理财项目还款计划
	 * @return
	 */
	@Action(value="/member_borrow/flow/projectRepayPlan",interceptorRefs = {
			@InterceptorRef("session"), @InterceptorRef("globalStack") })
	public String projectRepayPlan(){
		long id = paramLong("id");
		AdditionalFlowProject project = finanFlowQueryService.getFlowProjectById(id);
		request.setAttribute("projectName", project.getName());
		request.setAttribute("id", id);
		return "projectRepayPlan";
	}
	
	
	@Action(value="/member_borrow/flow/projectRepayPlanJson",interceptorRefs = {
			@InterceptorRef("session"), @InterceptorRef("globalStack") })
	public void projectRepayPlanJson() throws IOException{
		data =new HashMap<String, Object>();
		User user = this.getSessionUser();
		model.setUser(user);
		PageDataList<RepayPlanModel> repayPage = finanFlowQueryService.getRepayPlanPage(model);
		data.put("id", model.getId());
		data.put("data", repayPage);
		printWebJson(getStringOfJpaObj(data));
	}

}
